//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.wills.BaseDao;
import com.aidong.model.wills.SysMessageRead;
import java.util.Date;
import org.springframework.stereotype.Repository;

@Repository
public class SysMessageReadDao extends BaseDao<SysMessageRead, Integer> {
	public SysMessageReadDao() {
	}

	public boolean chkRead(int msgId, String userCode) {
		String sql = "select count(*) from SysMessageRead where msgId=:p1 and userCode=:p2";
		return ((Integer)this.getBySql(Integer.class, sql, new Object[]{Integer.valueOf(msgId), userCode})).intValue() > 0;
	}

	public void addRead(int msgId, String userCode) {
		if(!this.chkRead(msgId, userCode)) {
			SysMessageRead read = new SysMessageRead();
			read.setMsgId(Integer.valueOf(msgId));
			read.setUserCode(userCode);
			read.setReadTime(new Date());
			read.setDeleteLabel(Integer.valueOf(0));
			this.add(read);
		}

	}

	public void updateDelete(int msgId, String userCode) {
		SysMessageRead read = (SysMessageRead)this.getByWhere("msgId=:p1 and userCode=:p2", new Object[]{Integer.valueOf(msgId), userCode});
		if(read == null) {
			read = new SysMessageRead();
			read.setMsgId(Integer.valueOf(msgId));
			read.setUserCode(userCode);
			read.setReadTime(new Date());
			read.setDeleteLabel(Integer.valueOf(1));
			read.setDeleteTime(new Date());
			this.add(read);
		} else {
			read.setDeleteLabel(Integer.valueOf(1));
			read.setDeleteTime(new Date());
			this.update(read);
		}

	}
}
